﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace JustPlus
{
    public class GeneInfo
    {
        public string GeneID { get; set; }
        public string Photo { get; set; }
        public string NickName { get; set; }
        public string UserID { get; set; }
        public List<String> SingerName { get; set; }
        public string RadioID { get; set; }
        public GeneInfo()
        {
            SingerName = new List<string>();
        }
    }

    public class Muggy
    {
        public List<GeneInfo> MuggyList;
        public Muggy()
        {
            MuggyList = new List<GeneInfo>();
        }
        public void AddNewMuggy(string json)
        {
            MatchCollection groupmatch = Regex.Matches(json, @"""\d+"":\[\[.*?\],\[.*?\],"".+?""\]");
            //没有满足匹配的结果
            if (groupmatch.Count == 0)
                return;

            foreach (Match match in groupmatch)
            {
                GeneInfo geneinfo = new GeneInfo();
                String group = match.Value;
                MatchCollection infomatch = Regex.Matches(group, @""".*?""");
                if (infomatch.Count != 12)
                    return;
                geneinfo.GeneID = infomatch[0].Value.Trim('\"');
                geneinfo.Photo = Unescape(infomatch[1].Value).Trim('\"');
                geneinfo.NickName = (infomatch[2].Value).Trim('\"');
                geneinfo.UserID = (infomatch[3].Value).Trim('\"');
                if (geneinfo.SingerName != null)
                    geneinfo.SingerName.Clear();
                for (int j = 4; j <= 10; j++)
                {
                    geneinfo.SingerName.Add((infomatch[j].Value).Trim('\"'));
                }
                geneinfo.RadioID = infomatch[11].Value.Trim('\"');

                MuggyList.Add(geneinfo);
            }
        }

        private string Unescape(string s)
        {
            string tmp = "";
            tmp = s.Replace("\\/", "/");
            return tmp;
        }
    }
}
